<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>学生-查看就业信息</title>
    <link rel="stylesheet" href="${ctx}/static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctx}/static/css/index.css">
    <style>
        .layui-form-select dl {
            max-height: 260px;
        }
    </style>
</head>
<body>
<div class="body-head"><span>就业信息管理&nbsp;>&nbsp;查看就业信息</span></div>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script src="${ctx}/static/js/jquery.min.js"></script>
<script src="${ctx}/static/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->

<script>
    layui.use(['table', 'jquery', 'form', 'laydate'], function () {
        let table = layui.table;
        let $ = layui.$;
        let form = layui.form;
        let laydate = layui.laydate;

        laydate.render({
            elem: '#entryTime'
        });
        laydate.render({
            elem: '#resignationTime'
        });
        laydate.render({
            elem: '#attendanceTime',
            type: 'time'
        });
        laydate.render({
            elem: '#closingTime',
            type: 'time'
        });

        //温馨提示：默认由前端自动合计当前行数据。从 layui 2.5.6 开始： 若接口直接返回了合计行数据，则优先读取接口合计行数据。
        //详见：https://www.layui.com/doc/modules/table.html#totalRow
        table.render({
            elem: '#test',
            url: '${ctx}/student/getJobInfo.action',
            method: 'POST',
            toolbar: '#toolbarDemo',
            title: '就业信息表',
            page: true,
            limit: 10,
            limits: [3, 5, 10],
            cols: [
                [{
                    type: 'checkbox',
                    fixed: 'left'
                }, {
                    field: 'companyCode',
                    title: '单位代码',
                    align: 'center',
                    width: 120
                }, {
                    field: 'companyName',
                    title: '单位名称',
                    align: 'center',
                    width: 230
                }, {
                    field: 'city',
                    title: '城市',
                    align: 'center',
                    width: 80
                }, {
                    field: 'station',
                    title: '任职岗位',
                    align: 'center',
                    width: 150
                }, {
                    field: 'entryTime',
                    title: '入职时间',
                    align: 'center',
                    width: 120,
                    sort: true
                }, {
                    field: 'salary',
                    title: '工资',
                    align: 'center',
                    sort: true,
                    width: 80
                }, {
                    field: 'developmentLanguage',
                    title: '开发语言',
                    align: 'center',
                    width: 100
                }, {
                    field: 'dataBase',
                    title: '数据库',
                    align: 'center',
                    width: 100
                }, {
                    field: 'frame',
                    title: '框架',
                    align: 'center',
                    width: 140
                }, {
                    fixed: 'right',
                    align: 'center',
                    title: '操作',
                    toolbar: '#barDemo',
                    width: 150
                }]
            ],
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据，res为从url中get到的数据
                let result;
                if (this.page.curr) {
                    result = res.data.slice(this.limit * (this.page.curr - 1), this.limit * this.page.curr);
                } else {
                    result = res.data.slice(0, this.limit);
                }
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": result //解析数据列表
                }
            }
        });

        table.on('tool(test)', function (obj) {

            switch (obj.event) {
                case 'edit':
                    let data = obj.data;
                    //console.log(data);
                    layer.open({
                        type: 1,
                        area: ['1258px', '600px'],
                        title: '编辑',
                        content: $("#edit_form"),
                        shade: 0,
                        cancel: function (index) {
                            layer.closeAll();
                        }
                    });
                    //异步获取开发语言、数据库、框架信息
                    $.ajax({
                        type: 'post',
                        url: '${ctx}/student/getDevelopmentLanguageList.action',
                        success: function (data1) {
                            //console.log(data.developmentLanguage);
                            $.each(data1, function (index, value) {
                                //console.log(index+" "+value);
                                $.each(value, function (i, v) {
                                    //console.log(v.id+" "+v.developmentLanguage);
                                    if (v.developmentLanguage == data.developmentLanguage) {
                                        $("#developmentLanguage").append("<option value='" + v.id + "' selected>" + v.developmentLanguage + "</option>");
                                    } else {
                                        $("#developmentLanguage").append("<option value='" + v.id + "'>" + v.developmentLanguage + "</option>");
                                    }
                                });
                            });
                            form.render();
                        }
                    });
                    $.ajax({
                        type: 'post',
                        url: '${ctx}/student/getDataBaseList.action',
                        success: function (data1) {
                            //console.log(data.dataBases);
                            $.each(data1, function (index, value) {
                                $.each(value, function (i, v) {
                                    if (v.dataBase == data.dataBase) {
                                        $("#dataBase").append("<option value='" + v.id + "' selected>" + v.dataBase + "</option>")
                                    } else {
                                        $("#dataBase").append("<option value='" + v.id + "'>" + v.dataBase + "</option>")
                                    }
                                });
                            });
                            form.render();
                        }
                    });
                    $.ajax({
                        type: 'post',
                        url: '${ctx}/student/getFrameList.action',
                        success: function (data1) {
                            $.each(data1, function (index, value) {
                                $.each(value, function (i, v) {
                                    if (v.frame == data.frame) {
                                        $("#frame").append("<option value='" + v.id + "' selected>" + v.frame + "</option>")
                                    } else {
                                        $("#frame").append("<option value='" + v.id + "'>" + v.frame + "</option>")
                                    }
                                });
                            });
                            form.render();
                        }
                    });
                    //设置内容
                    $("#id").val(data.id);
                    $("#companyName").val(data.companyName);
                    $("#companyCode").val(data.companyCode);
                    $("#city").val(data.city);
                    $("#address").val(data.address);
                    $("#station").val(data.station);
                    $("#department").val(data.department);
                    $("#entryTime").val(data.entryTime);
                    $("#resignationTime").val(data.resignationTime);
                    $("#attendanceTime").val(data.attendanceTime);
                    $("#closingTime").val(data.closingTime);
                    $("#salary").val(data.salary);
                    $("#weal").val(data.weal);
                    $("#remark").val(data.remark);
                    //更新表单
                    form.render();
                    break;
                case 'del':
                    //获取学号
                    let id = obj.data.id;
                    // layer.msg(stuNo);
                    layer.confirm("删除后数据将无法恢复, 确定要删除吗？", {btn: ['确定', '取消'], title: "提示"}, function () {
                        $.ajax({
                            type: "post",
                            url: "${ctx}/student/deleteJob.action",
                            data: {id: id},
                            dataType: "json",
                            contentType: "application/x-www-form-urlencoded",
                            success: function (data) {
                                if (data.flag) {
                                    layer.msg("删除成功");
                                    setTimeout(() => {
                                        window.location.reload();
                                    }, 1500);
                                } else {
                                    layer.msg("删除失败");
                                }
                            },
                            error: function () {
                                layer.msg("请求失败");
                            }
                        });
                    });
                    break;
            }
        });

        $("#btn").on("click", function () {
            if ($("#companyName").val() == "") {
                layer.msg("公司名称项不能为空");
                return;
            } else if (!/^[0-9A-HJ-NPQRTUWXY]{8}-[0-9A-HJ-NPQRTUWXY]$/.test($("#companyCode").val())) {
                layer.msg("请输入正确的机构代码");
                return;
            } else if ($("#station").val() == "") {
                layer.msg("岗位项不能为空");
                return;
            } else if ($("#entryTime").val() == "") {
                layer.msg("入职时间不能为空");
            } else if (!/^\d+(\.\d+)?$/.test($("#salary").val())) {
                layer.msg("请输入正确的工资");
            } else {
                layer.confirm("确定要提交吗？", {btn: ['确定', '取消'], title: "提示"}, function () {
                    $.ajax({
                        type: "post",
                        url: "${ctx}/student/updateJob.action",
                        data: $("#edit_form").serialize(),
                        dataType: "json",
                        contentType: "application/x-www-form-urlencoded",
                        success: function (data) {
                            //console.log(data);
                            if (data.flag) {
                                layer.msg("修改成功");
                            } else {
                                layer.msg("修改失败");
                            }
                            setTimeout(() => {
                                window.location.reload()
                            }, 1500);

                        },
                        error: function () {
                            layer.msg("请求失败");
                        }
                    });
                    layer.closeAll('dialog');
                });
            }
        });

        $("#btnClose").on("click", function (index) {
            layer.closeAll();
        });

    });
</script>
<%--编辑表单弹出层--%>
<form class="layui-form" id="edit_form" style="display:none; margin-top: 16px">
    <input type="hidden" name="id" id="id" value="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">公司名称</label>
            <div class="layui-input-block" style="width: 250px;">
                <input type="text" name="companyName" id="companyName" class="layui-input"
                       lay-verify="companyName"
                       placeholder="请输入公司名称">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">机构代码</label>
            <div class="layui-input-block" style="width: 250px;">
                <input type="text" name="companyCode" id="companyCode" class="layui-input"
                       lay-verify="companyCode"
                       placeholder="请输入公司代码">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">出勤时间</label>
            <div class="layui-input-inline" style="width: 112px;">
                <input type="text" name="attendanceTime" id="attendanceTime" placeholder="上班时间"
                       lay-verify="attendanceTime"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid">-</div>
            <div class="layui-input-inline" style="width: 113px;">
                <input type="text" name="closingTime" id="closingTime" placeholder="下班时间" autocomplete="off"
                       lay-verify="closingTime"
                       class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">城市</label>
            <div class="layui-input-block" style="width: 250px;">
                <input type="text" name="city" id="city" class="layui-input" lay-verify="city"
                       placeholder="请输入单位所在城市(例：广州市)">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">详细地址</label>
            <div class="layui-input-block" style="width: 250px">
                <input type="text" name="address" id="address" class="layui-input" lay-verify="address"
                       placeholder="请输入公司详细地址">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">部门</label>
            <div class="layui-input-block" style="width: 250px">
                <input type="text" name="department" id="department" class="layui-input" lay-verify="department"
                       placeholder="请输入所在部门(例：研发部)">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">岗位</label>
            <div class="layui-input-block" style="width: 250px">
                <input type="text" name="station" id="station" class="layui-input" lay-verify="station"
                       placeholder="请输入就职岗位">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">入职日期</label>
            <div class="layui-input-block" style="width: 250px">
                <input type="text" name="entryTime" id="entryTime" autocomplete="off" class="layui-input"
                       lay-verify="entryTime"
                       placeholder="请选择入职日期">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">离职日期</label>
            <div class="layui-input-block" style="width: 250px">
                <input type="text" name="resignationTime" id="resignationTime" autocomplete="off" class="layui-input"
                       placeholder="请选择离职日期">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">月薪</label>
            <div class="layui-input-block" style="width: 250px">
                <input type="text" name="salary" id="salary" autocomplete="off" class="layui-input"
                       lay-verify="salary"
                       placeholder="请输入月薪(例：8000.00)">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">福利</label>
            <div class="layui-input-block" style="width: 624px">
                <input type="text" name="weal" id="weal" autocomplete="off" class="layui-input"
                       lay-verify="weal"
                       placeholder="请输入福利">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">开发语言</label>
            <div class="layui-input-block" style="width: 250px">
                <select name="developmentLanguage" id="developmentLanguage" lay-verify="developmentLanguage">
                    <option>--请选择--</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">数据库</label>
            <div class="layui-input-block" style="width: 250px">
                <select name="dataBase" id="dataBase" lay-verify="dataBase">
                    <option>--请选择--</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">主要框架</label>
            <div class="layui-input-block" style="width: 250px">
                <select name="frame" id="frame" lay-verify="frame" lay-search="">
                    <option>--请选择--</option>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item layui-form-text" style="width: 1257px">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block" style="width: 998px;">
                    <textarea placeholder="请在此输入您要说的话" name="remark" id="remark" class="layui-textarea"
                              lay-verify="remark"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-row">
        <div class="layui-col-md-offset5">
            <button type="button" id="btn" class="layui-btn layui-btn-normal">提交</button>
            <button type="button" id="btnClose" class="layui-btn layui-btn-primary">关闭</button>
        </div>
    </div>
</form>

<script src="${ctx}/static/js/index.js"></script>
</body>
</html>

